<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .outer-box{
            margin: 50px;
        }
        .outer-box .title{
            line-height: 100px;
            text-align: center;
            font-weight: 700;
            font-size: 20px;
        }
        .outer-box .block{
            width: 100%;
            margin: 20px 0;
        }
        .outer-box .block input{
            width: 100%;
            height: 40px;
            box-sizing: border-box;
            padding-left: 20px;
            border: 2px solid #ccc;
        }
        .outer-box .block:last-child input{
            color: white;
            padding: 0;
            background-color: rgb(68, 146, 254);
            border: none;
        }
    </style>
</head>
<body>
    <div class="outer-box">
        <div class="title">登录</div>
        <div class="block">
            <input type="text" placeholder="请输入用户名">
        </div>
        <div class="block">
            <input type="password" placeholder="请输入密码">
        </div>
        <div class="block">
            <input type="button" value="登录">
        </div>
    </div>

</body>
</html>

<script src="./ajax.js"></script>

<script>

    //获取输入框和按钮
    let ipts = document.querySelectorAll('.outer-box .block input');
    // console.log(ipts);
    //给按钮绑定点击事件
    ipts[2].onclick = ()=>{
        if(ipts[0].value && ipts[1].value){
            if(/^1[3-9]\d{9}$/.test(ipts[0].value)){
                ajax('get','https://yantianfeng.com/api/login',{username:ipts[0].value,password:ipts[1].value},function(data){
                    alert(data.msg);
                })
            }else{
                alert('用户名/密码格式错误!');
            }
        }else{
            alert('用户名/密码不能为空!');
        }
    }


</script>